//spu管理模块接口
import request from "@/utils/request";
import type {
  HasSpuResponseData,
  AllTradeMark,
  BaseSpuResponseData,
  AllSaleAttrResponseData,
} from "./type";
enum API {
  //获取SPU数据
  HASSPU_URL = "/admin/product/",
  //获取全部品牌的数据
  ALLTRADEMARK_URL = "/admin/product/baseTrademark/getTrademarkList",
  //获取spu基本信息(照片墙和已有的销售属性)
  BASESPU_URL = "/admin/product/getSpuInfo/",
  //全部的saleAttr
  ALLSALEATTR_URL = "/admin/product/baseSaleAttrList",
  //添加spu
  ADDSPU_URL = "/admin/product/saveSpuInfo",
  //更新spu
  UPDATESPU_URL = "/admin/product/updateSpuInfo",
  //追加一个新增的SKU地址
  ADDSKU_URL = "/admin/product/saveSkuInfo",
  //查看某一个已有的SPU下全部售卖的商品
  SKUINFO_URL = "/admin/product/findBySpuId/",
  //删除已有的spu
  REMOVESPU_URL = "/admin/product/deleteSpu/",
}
//获取SPU数据
export const reqHasSup = (
  page: number,
  limit: number,
  category3Id: number | string
) =>
  request.get<any, HasSpuResponseData>(
    API.HASSPU_URL + `${page}/${limit}?category3Id=${category3Id}`
  );
//获取全部品牌的数据
export const reqAllTradeMark = () =>
  request.get<any, AllTradeMark>(API.ALLTRADEMARK_URL);
//获取spu基本信息
export const reqBaseSpu = (supId: number) =>
  request.get<any, BaseSpuResponseData>(API.BASESPU_URL + supId);
//添加spu更新spu
export const reqAddSpuOrUpdateSpu = (data: any) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATESPU_URL, data);
  } else {
    return request.post<any, any>(API.ADDSPU_URL, data);
  }
};
//全部的saleAttr
export const reqAllSaleAttr = () =>
  request.get<any, AllSaleAttrResponseData>(API.ALLSALEATTR_URL);
//追加一个新增的SKU地址
export const reqAddSku = (data: any) =>
  request.post<any, any>(API.ADDSKU_URL + data);
//查看某一个已有的SPU下全部售卖的商品
export const reqSkuList = (spuId: number | string) =>
  request.get<any, any>(API.SKUINFO_URL + spuId);
//删除已有的spu
export const reqRemoveSpu = (spuId: number | string) =>
  request.delete(API.REMOVESPU_URL + spuId);
